﻿from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp                                        
from google.appengine.ext.webapp.util import run_wsgi_app      
from google.appengine.api import users
from google.appengine.api import mail
from entities import *
def signin():
    user = users.get_current_user()
    if user:  # signed in already
        greeting = '<em>' + user.nickname() +  '</em>! [<a href="' +users.create_logout_url('/') +'">Thoát</a>]' 
        return greeting
        #    user.nickname(), users.create_logout_url('/')
        #self.response.out.write('Xin chào <em>%s</em>! [<a href="%s">Thoát</a>]' % (
        #    user.nickname(), users.create_logout_url('/')))
    else: 
        greeting = ("<a  href=\"%s\">Đăng nhập/Đăng ký</a>." % users.create_login_url("/"))
        return greeting
        #self.response.out.write("<html><body>%s</body></html>" % greeting)
def insertGenre(name, description):
    genre = Genre()
    genre.name = unicode(name,'utf-8')
    genre.description = unicode(description,'utf-8')
    genre.put()
    return genre	
def init_start():
    #VaiTro.Add()
    #NguoiDung.Add("sunrises@gmail.com","http://test.net",6001)
    #TrangThai.Add('Vua nhap')
    #TrangThai.Add('Dang duyet')
    #TrangThai.Add('Hop le')
    #TrangThai.Add('Khong hop le')
    #LoaiHinh.Add('Ban thoi gian')
    #DoiTuong.Add(Entities.GetKey(),'Nguoi binh thuong',None,None)
    #MucLuong.Add('Thoa thuan')
    #LinhVuc.Add('Cong nghe thong tin')
    NganhNghe.Add_Admin('Cong nghe phan mem', 47001)
    NganhNghe.Add_Admin('Ban may tinh', 47001)
    NganhNghe.Add_Admin('Lap trinh web', 47001)
    #NganhNghe.Add(Entities.GetKey(),'Ban may tinh',77)
    #QuiMo.Add('Tu 1 - 5 nguoi')
    #TinhThanh.Add('Ha Noi')
    #CapBac.Add('Sinh vien thuc tap')
    #NganhNghe.Add(Entities.GetKey(),'Ban may tinh', 19001)
    #CapBac.Add('Sinh vien thuc tap')
    #DoiTuong.Add_Admin('Khiem thinh','Khong','Khong')
def sendMail(fr, to, subject, content):
    message = mail.EmailMessage(sender = fr,
                                subject = subject)
    message.to  = to
    message.body = content
    message.send()